<include file="Public/header"/>

<link href="__PUBLIC__/Admin/css/plugins/steps/jquery.steps.css" rel="stylesheet">
<link href="__PUBLIC__/Admin/css/plugins/iCheck/custom.css" rel="stylesheet">
<style>
    #page-wrapper{padding: 0 10px;}
    .wrapper{padding:0;}
    .ibox-content{padding: 15px 5px;}
    .form-control{display: inline-block;padding: 2px;height: 30px;}
    .input-xs{width: 40px;float:left;}
    .input-sm{width: 70px;}
    .input-s{width: 105px;}
    th{text-align: center;}
    .table > tbody > tr > td{padding: 2px;text-align: center;}
    .float-e-margins .btn{margin: 0;}
    .wizard-big.wizard > .content{min-height:500px;}
    .wizard > .content{background: #fff;border-top:2px solid #1AB394;border-radius: 0;}
    .wizard > .steps > ul > li{width: 12%;}
    .wizard > .content > .body{overflow-y:auto;height:100%;width: 100%;}
    .wizard > .content > .body{padding: 1% 0;}
    .label{cursor: pointer;}
    .wizard > .content > .body label.error{position: absolute;z-index: 100;margin-top: 5px;}
    .gybtn{ position: absolute;right: 0;margin-top: 5px;}
</style>

<div class="wrapper m-t">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <form id="form" action="{:U('Orders/putForm')}" method="post"class="wizard-big">
                <input type="hidden" name="rid" value="{$rid}"/>
                <h1>订单信息</h1>
                <fieldset>
                    <div style="width: 100%; overflow-x: auto;">
                        <table class="table-striped table table-bordered">
                            <thead>
                            <tr>
                                <th>订单编号</th>
                                <th colspan="2">
                                    <input type="text" value="{$result.order_number}" class="form-control input-s-sm pull-left" disabled="disabled"/>
                                </th>
                                <th>经销商</th>
                                <th colspan="2">
                                    <input type="text" value="{$result.company_name}" class="form-control pull-left" disabled="disabled"/>
                                </th>
                                <th>客户名称</th>
                                <th colspan="3">
                                    <input type="text" value="{$result.username}" class="form-control pull-left" disabled="disabled"/>
                                </th>
                                <th>订货日期</th>
                                <th colspan="3" class="date">
                                    <input type="text" value="{$result.order_time|date='Y-m-d H:i:s',###}"  class="form-control pull-left" disabled="disabled"/>
                                </th>
                                <th colspan="5"></th>
                            </tr>
                            <tr>
                                <th>商品分类</th>
                                <th>商品名称</th>
                                <th>门洞尺寸</th>
                                <th>门扇规格</th>
                                <th>立板规格</th>
                                <th>帽头规格</th>
                                <th>工艺分类</th>
                                <th>工艺技术</th>
                                <th>数量</th>
                                <th>线条长度</th>
                                <th>线条分类</th>
                                <th>线条型号</th>
                                <th>线条数量</th>
                                <th>门型</th>
                                <th>颜色</th>
                                <th>折扣</th>
                                <th>单价</th>
                                <th>总价</th>
                                <th>备注</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>
                                    <select name="product_cate[]" onchange="productlist(this,this.value)" class="form-control input-s">
                                        <option value="">请选择</option>
                                        <volist name="plist" id="vo">
                                            <option value="{$vo.id}">{$vo.cate_name}</option>
                                        </volist>
                                    </select>
                                </td>
                                <td>
                                    <select name="productName[]" class="form-control input-s">
                                        <option value="">请选择</option>
                                    </select>
                                </td>
                                <td>
                                    <input type="text" onblur="opening(this,this.value)" name="doorOpeningSize[]"  class="form-control input-s" placeholder="cm*cm*cm"/>
                                </td>
                                <td>
                                    <input type="text" id="msg" name="doorLeafStandard[]" class="form-control input-s" placeholder="cm*cm=cm"/>
                                </td>
                                <td>
                                    <input type="text" name="verticalPlate[]"  class="form-control input-s" placeholder="cm*cm=cm"/>
                                </td>
                                <td>
                                    <input type="text" name="cropupStandard[]"  class="form-control input-s" placeholder="cm*cm=cm"/>
                                </td>
                                <td>
                                    <select class="form-control input-s" name="craftcate[]" onchange="craflist(this,this.value)">
                                        <option value="">请选择</option>
                                        <volist name="cre" id="vo">
                                            <option value="{$vo.id}">{$vo.craft_name}</option>
                                        </volist>
                                    </select>
                                </td>
                                <td>
                                    <select name="craft_name[]" class="form-control input-s">
                                        <option value="">请选择</option>
                                    </select>
                                </td>
                                <td>
                                    <input type="text" value="1" name="Numbers[]"  class="form-control input-xs"/>
                                </td>
                                <td>
                                    <select name="linelength[]" class="form-control input-s">
                                        <option value="">选择</option>
                                        <volist name="lenth" id="vo">
                                            <option value="{$vo.lenth_value}">{$vo.lenth_value}</option>
                                        </volist>
                                    </select>
                                </td>
                                <td>
                                    <select class="form-control input-s" name="line_cate[]" onchange="linelist(this,this.value)">
                                        <option value="">请选择</option>
                                        <volist name="line" id="vo">
                                            <option value="{$vo.id}">{$vo.line_name}</option>
                                        </volist>
                                    </select>
                                </td>
                                <td>
                                    <select name="linetype[]" class="form-control input-s">
                                        <option value="">请选择</option>
                                    </select>
                                </td>
                                <td>
                                    <input name="wireNumber[]" value="1" type="text" class="form-control input-sm"/>
                                </td>
                                <td>
                                    <select name="goal_name[]" class="form-control input-s">
                                        <option value="">请选择</option>
                                        <volist name="menxin" id="vo">
                                            <option value="{$vo.gname}">{$vo.gname}</option>
                                        </volist>
                                    </select>
                                </td>
                                <td>
                                    <select name="color[]" class="form-control input-s">
                                        <option value="">请选择</option>
                                         <volist name="colors" id="vo">
                                            <option value="{$vo.color_number}">{$vo.color_number}</option>
                                         </volist>
                                    </select>
                                </td>
                                <td>
                                    <input type="text" value="1"  name="discount[]" class="form-control input-xs"/>
                                </td>
                                <td>
                                    <input onblur="prices(this,this.value)"  type="text" name="price[]"  class="form-control input-xs"/>
                                </td>
                                <td>
                                    <input type="text"  name="totalPrice[]" class="form-control input-sm"/>
                                </td>
                                <td>
                                    <input type="text" name="remark[]" class="form-control input-sm"/>
                                </td>
                                <td>
                                    <div class="btn-group" style="width: 60px;">
                                        <button class="btn btn-info btn-sm addBtn" type="button">+</button>
                                        <button class="btn btn-danger btn-sm deletBtn" type="button">x</button>
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="clearfix"></div>
                    <div class="hr-line-dashed"></div>
                    <div>
                        <div class="col-md-2">
                            <div class="input-group m-b">
                                <span class="input-group-addon">总款</span>
                                <input onblur="zongkuan(this.value)" name="order_price" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="col-md-2">
                            <div class="input-group m-b">
                                <span class="input-group-addon">定金</span>
                                <input onblur="dingjin(this.value)" type="text" name="downPayment" class="form-control">
                            </div>
                        </div>
                        <div class="col-md-2">
                            <div class="input-group m-b">
                                <span class="input-group-addon">余款</span>
                                <input name="sparemoney" type="text"  class="form-control">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="input-group m-b">
                                <span class="input-group-addon">备注</span>
                                <input name="orderRemark" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </fieldset>


                <h1>工序信息</h1>
                <fieldset>
                    <div class="ibox-content" id="gy" style="padding-bottom:0;border: none;">
                        <div class="gongyibox">


                            <div class="col-lg-2">
                                <div class="input-group m-b">
                                    <span class="input-group-addon bg-info">工序</span>
                                    <input type="text" class="form-control" name="processName[]" required>
                                </div>
                            </div>
                            <div class="col-lg-2">
                                <div class="input-group m-b">
                                    <span class="input-group-addon bg-info">工价</span>
                                    <input type="number" class="form-control" name="labourCost[]" required>
                                </div>
                            </div>
                            <div class="col-lg-2">
                                <div class="input-group m-b">
                                    <span class="input-group-addon">操作工</span>
                                    <input type="text" class="form-control" name="constructionWorker[]">
                                </div>
                            </div>
                            <div class="col-lg-3">
                                <div class="input-group m-b date">
                                    <span class="input-group-addon">要求完成时间</span>
                                    <input type="text" class="form-control" name="requireTime[]">
                                </div>
                            </div>
                            <div class="col-lg-3">
                                <span class="btn btn-primary btn-xs m-r addGongyi"><i class="fa fa-plus"></i></span>
                                <span class="btn btn-danger btn-xs m-t-xs removeGongyi hidden"><i class="fa fa-times"></i></span>
                            </div>


                            <div class="clearfix"></div>
                        </div>
                    </div>

                </fieldset>

                <h1>原材料信息</h1>
                <fieldset>

                    <div class="input-group">
                        <input type="text" placeholder="请输入货品编号或名称" value="" class="form-control" id="search">
                        <span class="input-group-addon search" style="cursor: pointer;">添加</span>

                        <div class="input-group-btn">
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>

                    </div>

                    <div id="cailiao" class="m-t"></div>

                </fieldset>
            </form>
        </div>
    </div>
</div>

<include file="Public/footer"/>
<!-- Steps -->
<script src="__PUBLIC__/Admin/js/plugins/staps/jquery.steps.min.js"></script>
<script src="__PUBLIC__/Admin/js/plugins/staps/Mystaps.js"></script>

<script src="__PUBLIC__/Admin/js/bootstrap-suggest.min.js"></script>

<!-- Jquery Validate -->
<script src="__PUBLIC__/Admin/js/plugins/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/Admin/js/plugins/validate/messages_zh.min.js"></script>

<script src="__PUBLIC__/Admin/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="__PUBLIC__/Admin/js/tianchen.js"></script>
<script>
    $(function(){
        var addHtml=$('table tbody tr:first').prop('outerHTML');
        $('body').on('click','.addBtn',function(){
            $('table tbody tr:last').after(addHtml);
        }).on('click','.deletBtn',function(){
            $(this).parents('tr').remove();
        });
       
        

        function initTest() {
            $("#search").bsSuggest('init', {
                allowNoKeyword: false,
                getDataMethod: 'firstByUrl',
                url: "{:U('Stock/test')}",
                idField: "userId",
                keyField: "userName"
            }).on('onDataRequestSuccess', function (e, result) {
                console.log('onDataRequestSuccess: ', result);
            }).on('onSetSelectValue', function (e, keyword, data) {
                console.log('onSetSelectValue: ', keyword, data);
            }).on('onUnsetSelectValue', function () {
                console.log('onUnsetSelectValue');
            });
        }

        initTest()


        $('.search').click(function () {
            var keywords = $("#search").val();
            if (keywords == '') {
                layer.alert('请输入关键词');
                return;
            }
            var data = '';
            $.post("{:U('Stock/search')}", {keywords: keywords}, function (re) {
                if (re.state == 'success') {
                    var info = re.info;
                    data += '<div class="cailiaobox">';
                    data += '<div class="col-lg-2"><div class="input-group m-b">';
                    data += '<span class="input-group-addon">编号</span>';
                    data += '<input type="text" class="form-control" readonly="readonly" value="' + info.m_number + '"></div></div>';
                    data += '<div class="col-lg-2"><div class="input-group m-b">';
                    data += '<span class="input-group-addon">名称</span>';
                    data += '<input type="text" class="form-control" readonly="readonly" value="' + info.m_name + '"></div></div>';
                    data += '<div class="col-lg-2"><div class="input-group m-b">';
                    data += '<span class="input-group-addon">规格</span>';
                    data += '<input type="text" class="form-control" readonly="readonly" value="' + info.standard + '"></div></div>';
                    data += '<div class="col-lg-2"><div class="input-group m-b ">';
                    data += '<span class="input-group-addon">价格</span>';
                    data += '<input type="text" class="form-control" readonly="readonly" value="' + info.bid_price + '"></div></div>';
                    data += '<div class="col-lg-2"><div class="input-group m-b ">';
                    data += '<span class="input-group-addon">条码</span>';
                    data += '<input type="text" class="form-control" readonly="readonly" name="bracode[]" value="' + info.bracode + '"></div></div>';
                    data += '<div class="col-lg-2"><div class="input-group m-b ">';
                    data += '<span class="input-group-addon">数量</span>';
                    data += '<input type="number" class="form-control" name="counts[]" value="1"></div></div>';
                    data += '<div class="gybtn"><span class="closebtn pull-right"><i class="glyphicon glyphicon-remove-sign text-info"></i></span></div>';
                    data += '<div class="clearfix"></div></div>';
                    $('#cailiao').append(data);
                } else {
                    layer.alert('没有这个货品');
                    return;
                }
            })


        });

    });

    //门扇、立板、冒头规格的参数
    var ms_length = '';//门扇长
    var ms_witch = '';//门扇宽
    var ms_value = '';//门扇默认值
    var lb_length = '';//立板长
    var lb_witch = '';//立板宽
    var lb_value = '';//立板默认值
    var mt_length = '';//冒头长
    var mt_witch = '';//冒头宽
    var mt_value = '';//冒头默认值

    //获取商品信息
    function productlist(that, pid) {
        if(pid==''){
            $(that).parents('tr').find("[name='productName[]']").html('<option value="">请选择</option>');
            return false;
        }
        //根据商品分类id获取订单基础参数
        $.post("{:U('Login/getparma')}",{pid:pid},function (data) {
           if(data.state=='error'){
               layer.alert(data.info);
               return false;
           }else{
               var info=data.info;
               ms_length=parseInt(info.ms_length);
               ms_witch=parseInt(info.ms_witch);
               ms_value=info.ms_value;
               lb_length=parseInt(info.lb_length);
               lb_witch=parseInt(info.lb_witch);
               lb_value=info.lb_value;
               mt_length=parseInt(info.mt_length);
               mt_witch=parseInt(info.mt_witch);
               mt_value=info.mt_value;
           }
        })

        var ptext = '';
        $.post("{:U('OrderSet/productList')}", {pid: pid}, function (data) {
            if(data !== ''){
                $.each(data, function (k, v) {
                    ptext += "<option value='" + v.cate_name + "'>" + v.cate_name + "</option>";
                })
            }

            $(that).parents('tr').find("[name='productName[]']").html(ptext);
        })
    }

    //通过门洞尺寸计算其他规格
    function opening(that, valid) {
        valid = valid.NoSpace();//门洞规格
        var re = valid.split('*');
        var lengths = parseInt(re[0]);
        var witchs = parseInt(re[1]);

        var ms = (lengths + ms_length) + '*' + (witchs + ms_witch) + '=' + ms_value;//门扇规格
        var lb = (lengths + lb_length) + '*' + (witchs + lb_witch) + '=' + lb_value;//立板规格
        var mt = (lengths + mt_length) + '*' + (witchs + mt_witch) + '=' + mt_value;//冒头规格
        $(that).parents('tr').find("[name='doorLeafStandard[]']").val(ms);
        $(that).parents('tr').find("[name='verticalPlate[]']").val(lb);
        $(that).parents('tr').find("[name='cropupStandard[]']").val(mt);

    }
    //获取工艺信息
    function craflist(that, pid) {
        if(pid == ''){
            $(that).parents('tr').find("[name='craft_name[]']").html('<option value="">请选择</option>');
            return false;
        }
        var ctext = '';
        $.post("{:U('OrderSet/craftsList')}", {pid: pid}, function (data) {
            $.each(data, function (k, v) {
                ctext += "<option value='" + v.craft_name + "'>" + v.craft_name + "</option>";
            })
            $(that).parents('tr').find("[name='craft_name[]']").html(ctext);
        })
    }
    //获取线条型号信息
    function linelist(that, pid) {
        if(pid == ''){
            $(that).parents('tr').find("[name='linetype[]']").html('<option value="">请选择</option>');
            return false;
        }
        var ltext = '';
        $.post("{:U('OrderSet/linelist')}", {pid: pid}, function (data) {
            $.each(data, function (k, v) {
                ltext += "<option value='" + v.line_name + "'>" + v.line_name + "</option>";
            })
            $(that).parents('tr').find("[name='linetype[]']").html(ltext);
        })
    }
    //计算总价
    function prices(that, pval) {
        var price = parseFloat(pval);//单价
        var number = $(that).parents('tr').find("[name='Numbers[]']").val();
        var discount = $(that).parents('tr').find("[name='discount[]']").val();
        $(that).parents('tr').find("[name='totalPrice[]']").val(price * number * parseFloat(discount));
    }
    //工序操作
    var gongyiHTML=$('.gongyibox').prop('outerHTML');
    $("body").on('click','.addGongyi',function(){
        $('#gy').append(gongyiHTML);
        $('.removeGongyi:not(.removeGongyi:first)').removeClass('hidden');
    }).on('click','.removeGongyi',function(){
        $(this).parents('.gongyibox').remove();
    });
    
      //定金计算
    function zongkuan(din) {
        var order_price = $("[name='order_price']").val();
        $("[name='downPayment']").val(order_price * 0.3);
        $("[name='sparemoney']").val(order_price * 0.7);
    }


    //余款计算
    function dingjin(val) {
        var order_price = $("[name='order_price']").val();
        $("[name='sparemoney']").val(order_price - val);
    }

</script>



